package com.zcx.qshop.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.R;
import com.zcx.qshop.conn.JsonUsernameAsyGet;
import com.zcx.qshop.view.TitleView;

/**
 * Created by Administrator on 2015/8/28 0028.
 */
public class EditNameActivity extends QSActivity {

    @BoundView(R.id.title_view) private TitleView titleView;

    @BoundView(R.id.edit_name_name) private TextView name;

    @BoundView(R.id.edit_name_save) private View save;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_edit_name);

        titleView.showStyle(TitleView.Style.FULL);

        titleView.showType(TitleView.Type.BACK_TWO, TitleView.Type.NAME_ONE);

        titleView.setTitleName("修改昵称");

        titleView.setOnTitleItemClickListener(new TitleView.OnTitleItemClickListener() {

            @Override
            public void onBackClick() {

                finish();

            }

        });

        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                new JsonUsernameAsyGet(QSApplication.QSPreferences.readUid(), name.getText().toString(), new AsyCallBack<String>(){

                    @Override
                    public void onSuccess(String toast, int type, String s) throws Exception {

                        QSApplication.LoginAction.setName(s);

                        finish();

                    }

                }).execute(EditNameActivity.this);

            }
        });

    }

}
